from django.db import models
from home.models import User

# Create your models here.

class ArticleCategory(models.Model):
    category_name=models.CharField(verbose_name="文章类别",max_length=50)
    create_user=models.ForeignKey(User,on_delete=models.PROTECT,related_name='created_category_user')
    update_user=models.ForeignKey(User,on_delete=models.PROTECT,related_name='update_category_user')
    class Meta:
        db_table='article_category'

class Article(models.Model):
    category=models.ForeignKey(ArticleCategory,on_delete=models.PROTECT)
    article_img=models.ImageField(verbose_name="文章图片",null=True)
    article_title=models.CharField(verbose_name="文章标题",max_length=100)
    article_intro=models.CharField(verbose_name="文章简介",max_length=100,null=True,blank=True)
    article_content=models.TextField(verbose_name="文章内容")
    article_views=models.IntegerField(verbose_name="文章浏览量", default=0)
    address_link=models.CharField(verbose_name="地址链接",max_length=255)
    publish_time=models.DateTimeField(verbose_name="发布时间",auto_now=True)
    create_user=models.ForeignKey(User,on_delete=models.PROTECT,related_name='created_articles_user')
    update_user=models.ForeignKey(User,on_delete=models.PROTECT,related_name='update_articles_user')
    create_time=models.DateTimeField(verbose_name="创建时间",auto_now_add=True)
    update_time=models.DateTimeField(verbose_name="修改时间",auto_now=True)
    deleted=models.BooleanField(verbose_name="逻辑删除", default=False)
    class Meta:
        db_table='article'
        verbose_name="文章"
        verbose_name_plural=verbose_name

class Comments(models.Model):
    article=models.ForeignKey(Article,on_delete=models.CASCADE)
    comments_time=models.DateTimeField(verbose_name="评论时间",auto_now_add=True)
    comments_content=models.CharField(verbose_name="评论内容",max_length=255)
    create_user = models.ForeignKey(User, on_delete=models.CASCADE,related_name="create_comments_user")
    update_user = models.ForeignKey(User, on_delete=models.CASCADE,related_name="update_comments_user")
    class Meta:
        db_table='comments'

